package components.managers
{
	import components.contorls.superClass.BaseTextArea;
	import components.contorls.superClass.BaseTextInput;
	import components.core.UIComponent;
	
	public class FocusManager
	{
		private static var _currentFocusComp:UIComponent;
		
		public function FocusManager()
		{
		}
		
		public static function get currentFocusComp():UIComponent
		{
			return _currentFocusComp;
		}
		
		public static function set currentFocusComp(value:UIComponent):void
		{
			if (_currentFocusComp == value || (value && !value.focusEnable) || (value && value.stage==null))
				return;
			
			if (_currentFocusComp)
			{
				_currentFocusComp.focusOut();
				_currentFocusComp = null;
			}
			
			_currentFocusComp = value;
			
			if (_currentFocusComp)
			{
				_currentFocusComp.focusIn();
				
				if (!(_currentFocusComp is BaseTextInput) &&
					!(_currentFocusComp is BaseTextArea) && SystemManager.rootStage)
					SystemManager.rootStage.focus = _currentFocusComp;
			}
			else
				SystemManager.rootStage.focus=SystemManager.rootStage;
			
		}
		
	}
}